package datastructure.tree;

/**
 * Given a sorted array, build a binary tree with minimum height
 * 
 * @author Lei
 */
public class BuildBinaryTreeWithMiniHeight {

    public static TreeNode buildBinaryTreeWithMiniHeight(int[] arr, int start, int end) {
        if (end < start) {
            return null;
        }

        int middle = (start + end) / 2;
        TreeNode n1 = new TreeNode(arr[middle]);
        n1.left = buildBinaryTreeWithMiniHeight(arr, start, middle - 1);
        n1.right = buildBinaryTreeWithMiniHeight(arr, middle + 1, end);

        return n1;
    }
    
    public static void main(String[] args) {
        int[] arr = { 5,7,9, 11, 13};
         TreeNode n = BuildBinaryTreeWithMiniHeight.buildBinaryTreeWithMiniHeight(arr,0,arr.length - 1);
        
         PrintLevelOrder.printLevelOrder(n);
         
    }
    
}
